package kz.pompei.ifacer.main;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import kz.pompei.ifacer.main.align.AlignFrame;
import kz.pompei.ifacer.main.toolbar.AdditionToolBar;
import kz.pompei.ifacer.main.toolbar.BottomToolBar;
import kz.pompei.ifacer.main.toolbar.TopToolBar;
import kz.pompei.ifacer.util.Handler;

public class MainFramePanel extends JPanel {
  
  public final GrotTabPanel grotTabPanel;
  
  public MainFramePanel(KeyManager keyManager, AlignFrame alignFrame) throws Exception {
    setLayout(new BorderLayout());
    GrotTabPanel grotTabPanel = new GrotTabPanel();
    this.grotTabPanel = grotTabPanel;
    
    final ActionManager actionManager = new ActionManager(grotTabPanel);
    actionManager.update();
    TopToolBar mainToolBar = new TopToolBar(actionManager, alignFrame);
    alignFrame.init(actionManager);
    
    AdditionToolBar additionToolBar = new AdditionToolBar(actionManager.additionActions);
    
    BottomToolBar bottomToolBar = new BottomToolBar(grotTabPanel);
    
    grotTabPanel.updates.add(new Handler() {
      @Override
      public void handle() throws Exception {
        actionManager.update();
      }
    });
    
    add(mainToolBar.source, BorderLayout.PAGE_START);
    add(additionToolBar.source, BorderLayout.WEST);
    add(grotTabPanel, BorderLayout.CENTER);
    add(bottomToolBar.source, BorderLayout.PAGE_END);
    
    KeysAndActions.configure(keyManager, actionManager);
  }
}
